<script>
		function agregarDescuento(total, descuento){
			var c = $('#utilizarPromo').attr('checked');
			if (c) {
				$('#subtotal_pago').attr('value',''+(total*(1-descuento/100)).toFixed(2));
				$('#igv_pago').attr('value',''+(0.18*total*(1-descuento/100)).toFixed(2));
				$('#total_a_pagar_sol').attr('value',''+((total*(1-descuento/100))+(0.18*total*(1-descuento/100))).toFixed(2));
				$('#total_a_pagar_dol').attr('value',''+(((total*(1-descuento/100))+(0.18*total*(1-descuento/100)))/2.7).toFixed(2));
			}
			else {
				$('#subtotal_pago').attr('value',''+total.toFixed(2));
				$('#igv_pago').attr('value',''+(0.18*total).toFixed(2));
				$('#total_a_pagar_sol').attr('value',''+(total+0.18*total).toFixed(2));
				$('#total_a_pagar_dol').attr('value',''+((total+0.18*total)/2.7).toFixed(2));
			}
		}
</script>

<%= form_for(@nuevo_ticket, :url=> tickets_path, :method=>'post') do |f| %>
	<h2>Registrar venta - Paso 4</h2>
	<table>
	<tr><td><b>Codigo:</b></td><td><%= text_field_tag "", @viaje.codigo, :class => "MiTextField1", :readonly => true %></td></tr>
	<tr><td><b>Salida:</b></td><td><%= text_field_tag "", @viaje.station_salida.ciudad, :class => "MiTextField1", :readonly => true %></td></tr>
	<tr><td><b>Llegada:</b></td><td><%= text_field_tag "", @viaje.station_llegada.ciudad, :class => "MiTextField1", :readonly => true %></td></tr>
	<tr><td><b>Fecha/Hora:</b></td><td><%= text_field_tag "", @viaje.fechaHoraViaje.in_time_zone("Lima").to_formatted_s(:short), :class => "MiTextField1", :readonly => true %></td></tr>
	</table>

	<% if @mensaje == "RESERVA" %>
		<%= field_set_tag "Información sobre el pago", :class => "MiFieldSet1" do %>
			<table>
			<tr>
			<td><%= label_tag "Subtotal (S/.)" %></td>
			<% if @utilizarPromo == "PROMO" %>
				<td><%= text_field_tag 'subtotal_pago', number_with_precision((@viaje.precio / 1.18)*@reservas.size*(1-@descuento.to_f/100), :precision => 2), :class => "MiTextField1", :readonly => true%></td>
			<% else %>
				<td><%= text_field_tag 'subtotal_pago', number_with_precision((@viaje.precio / 1.18)*@reservas.size, :precision => 2), :class => "MiTextField1", :readonly => true%></td>
			<% end %>
			</tr>
			<tr>
			<td><%= label_tag "IGV (18%)" %></td>
			<% if @utilizarPromo == "PROMO" %>
				<td><%= text_field_tag 'igv_pago', number_with_precision(@viaje.precio*@reservas.size*(1-@descuento.to_f/100)-((@viaje.precio / 1.18)*@reservas.size*(1-@descuento.to_f/100)), :precision => 2), :class => "MiTextField1", :readonly => true %></td>
			<% else %>
				<td><%= text_field_tag 'igv_pago', number_with_precision(@viaje.precio*@reservas.size-((@viaje.precio / 1.18)*@reservas.size), :precision => 2), :class => "MiTextField1", :readonly => true %></td>
			<% end %>
			</tr>
			<tr>
			<td><%= label_tag "Total a pagar (S/.)" %></td>
			<% if @utilizarPromo == "PROMO" %>
				<td><%= text_field_tag 'total_a_pagar_sol', number_with_precision((@viaje.precio)*@reservas.size*(1-@descuento.to_f/100), :precision => 2), :class => "MiTextField1", :readonly => true %></td>
			<% else %>
				<td><%= text_field_tag 'total_a_pagar_sol', number_with_precision((@viaje.precio)*@reservas.size, :precision => 2), :class => "MiTextField1", :readonly => true %></td>
			<% end %>
			</tr>
			<tr>
			<td><%= label_tag "Total a pagar (US$)" %></td>
			<% if @utilizarPromo == "PROMO" %>
				<td><%= text_field_tag 'total_a_pagar_dol', number_with_precision((@viaje.precio)*@reservas.size*(1-@descuento.to_f/100)/2.7, :precision => 2), :class => "MiTextField1", :readonly => true %></td>
			<% else %>
				<td><%= text_field_tag 'total_a_pagar_dol', number_with_precision((@viaje.precio)*@reservas.size/2.7, :precision => 2), :class => "MiTextField1", :readonly => true %></td>
			<% end %>
			</tr>
			<tr>
			<td><%= label_tag "Efectivo" %></td>
			<td style="text-align: right;"><%= label_tag "S/." %></td>
			<td><%= text_field_tag 'pago_efec_sol', "", :class => "MiTextField1" %></td>
			<td><%= label_tag "US$" %></td>
			<td><%= text_field_tag 'pago_efec_dol', "", :class => "MiTextField1" %></td>
			</tr>
			<tr>
			<td><%= label_tag "Tarjeta de crédito" %></td>
			<td style="text-align: right;"><%= label_tag "S/." %></td>
			<td><%= text_field_tag 'pago_tc_sol', "", :class => "MiTextField1" %></td>
			<td><%= label_tag "US$" %></td>
			<td><%= text_field_tag 'pago_tc_dol', "", :class => "MiTextField1" %></td>
			</tr>
			<tr>
			<td><%= label_tag "Tarjeta de débito" %></td>
			<td style="text-align: right;"><%= label_tag "S/." %></td>
			<td><%= text_field_tag 'pago_td_sol', "", :class => "MiTextField1" %></td>
			<td><%= label_tag "US$" %></td>
			<td><%= text_field_tag 'pago_td_dol', "", :class => "MiTextField1" %></td>
			</tr>
			</table>
			<%= f.submit "Registrar venta", :class => "MiBoton1", :style => "margin-right: 5px; margin-bottom: 5px; padding-left: 0px; margin-top: 10px; width: 150px;" %>
			<%= hidden_field_tag "viaje_id", @viaje.id %>
			<%= hidden_field_tag "tipoVenta", @mensaje == "RESERVA" ? "Reserva" : "Directa" %>
			<% @tipo_doc.each_pair do |td1, td2| %>
				<%= hidden_field_tag "tipo_doc[#{td1}]", td2 %>
			<% end %>
			<% @nro_documento.each_pair do |nd1, nd2| %>
				<%= hidden_field_tag "nro_documento[#{nd1}]", nd2 %>
			<% end %>
			<% @nombre.each_pair do |n1, n2| %>
				<%= hidden_field_tag "nombre[#{n1}]", n2 %>
			<% end %>
			<% @ape_pat.each_pair do |ap1, ap2| %>
				<%= hidden_field_tag "ape_pat[#{ap1}]", ap2 %>
			<% end %>
			<% @ape_mat.each_pair do |am1, am2| %>
				<%= hidden_field_tag "ape_mat[#{am1}]", am2 %>
			<% end %>
			<% @tipo_comida.each_pair do |tc1, tc2| %>
				<%= hidden_field_tag "tipo_comida[#{tc1}]", tc2 %>
			<% end %>
			<% @genero_pelicula.each_pair do |gp1, gp2| %>
				<%= hidden_field_tag "genero_pelicula[#{gp1}]", gp2 %>
			<% end %>
			<%= hidden_field_tag "codigoReserva", @reservas[0].codigo %>
			<%= hidden_field_tag "nro_doc_pasajero_frec", @nro_doc_pasajero_frec %>
			<%= hidden_field_tag "utilizarPromo", @utilizarPromo %>
			<%= hidden_field_tag "ptos_requeridos", @ptos_requeridos %>
			<%= hidden_field_tag "descuento", @descuento %>
			<%= hidden_field_tag "promocion_id", @promocion.size > 0 ? @promocion.id : -1 %>
		<% end %>
	<% elsif @mensaje == "DIRECTA" %>
		<%= field_set_tag "Descuentos de pasajero frecuente", :class => "MiFieldSet1" do %>
			<%= @promocion.size %>
			<p>Ingrese el número de documento del pasajero frecuente del cual se descontarán los puntos</p>
			<table>
			<tr>
			<td><%= label_tag "Nro. de documento" %></td>
			<td><%= text_field_tag 'nro_doc_pasajero_frec', "", :class => "MiTextField1", :readonly => (@promocion.size > 0 ? false : true) %></td>
			</tr>
			<tr>
			<td><%= label_tag "Puntos requeridos" %></td>
			<td><%= text_field_tag 'ptos_requeridos', (@promocion.size > 0 ? number_with_precision(@promocion[0].puntos, :precision=>0) : "No existe promoción"), :class => "MiTextField1", :readonly => true %></td>
			</tr>
			<tr>
			<td><%= label_tag "Descuento (%)" %></td>
			<td><%= text_field_tag 'descuento', (@promocion.size > 0 ? number_with_precision(@promocion[0].descuento, :precision => 2) : "No existe promoción"), :class => "MiTextField1", :readonly => true %></td>
			</tr>
			<tr>
			<td><%= label_tag "Utilizar promoción" %></td>
			<td><%= check_box_tag "utilizarPromo", (@promocion.size > 0 ? "PROMO" : ""), false, :disabled => (@promocion.size > 0 ? false : true), :onclick => (@promocion.size == 0 ? "" : "agregarDescuento(#{(@viaje.precio / 1.18)*@asiento.size},#{@promocion[0].descuento})") %></td>
			</tr>
			</table>
		<% end %>
		<%= field_set_tag "Información económica", :class => "MiFieldSet1" do %>
			<table>
			<tr>
			<td><%= label_tag "Costo por boleto (S/.)" %></td>
			<td><%= text_field_tag 'costo_boleto_sol', number_with_precision(@viaje.precio, :precision => 2), :class => "MiTextField1", :readonly => true %></td>
			</tr>
			<tr>
			<td><%= label_tag "Costo con dscto. (S/.)" %></td>
			<td><%= text_field_tag 'costo_boleto_dscto_sol', (@promocion.size > 0 ? number_with_precision(@viaje.precio*(1-@promocion[0].descuento/100), :precision => 2) :number_with_precision(@viaje.precio, :precision => 2)), :class => "MiTextField1", :readonly => true %></td>
			</tr>
			</table>
		<% end %>
		<%= field_set_tag "Información sobre el pago", :class => "MiFieldSet1" do %>
			<table>
			<tr>
			<td><%= label_tag "Subtotal (S/.)" %></td>
			<td><%= text_field_tag 'subtotal_pago', number_with_precision((@viaje.precio / 1.18)*@asiento.size, :precision => 2), :class => "MiTextField1", :readonly => true%></td>
			</tr>
			<tr>
			<td><%= label_tag "IGV (18%)" %></td>
			<td><%= text_field_tag 'igv_pago', number_with_precision(@viaje.precio*@asiento.size-((@viaje.precio / 1.18)*@asiento.size), :precision => 2), :class => "MiTextField1", :readonly => true %></td>
			</tr>
			<tr>
			<td><%= label_tag "Total a pagar (S/.)" %></td>
			<td><%= text_field_tag 'total_a_pagar_sol', number_with_precision((@viaje.precio)*@asiento.size, :precision => 2), :class => "MiTextField1", :readonly => true %></td>
			</tr>
			<tr>
			<td><%= label_tag "Total a pagar (US$)" %></td>
			<td><%= text_field_tag 'total_a_pagar_dol', number_with_precision((@viaje.precio)*@asiento.size/2.7, :precision => 2), :class => "MiTextField1", :readonly => true %></td>
			</tr>
			<tr>
			<td><%= label_tag "Efectivo" %></td>
			<td style="text-align: right;"><%= label_tag "S/." %></td>
			<td><%= text_field_tag 'pago_efec_sol', "", :class => "MiTextField1" %></td>
			<td><%= label_tag "US$" %></td>
			<td><%= text_field_tag 'pago_efec_dol', "", :class => "MiTextField1" %></td>
			</tr>
			<tr>
			<td><%= label_tag "Tarjeta de crédito" %></td>
			<td style="text-align: right;"><%= label_tag "S/." %></td>
			<td><%= text_field_tag 'pago_tc_sol', "", :class => "MiTextField1" %></td>
			<td><%= label_tag "US$" %></td>
			<td><%= text_field_tag 'pago_tc_dol', "", :class => "MiTextField1" %></td>
			</tr>
			<tr>
			<td><%= label_tag "Tarjeta de débito" %></td>
			<td style="text-align: right;"><%= label_tag "S/." %></td>
			<td><%= text_field_tag 'pago_td_sol', "", :class => "MiTextField1" %></td>
			<td><%= label_tag "US$" %></td>
			<td><%= text_field_tag 'pago_td_dol', "", :class => "MiTextField1" %></td>
			</tr>
			</table>
			<%= f.submit "Registrar venta", :class => "MiBoton1", :style => "margin-right: 5px; margin-bottom: 5px; padding-left: 0px; margin-top: 10px; width: 150px;" %>
			<%= hidden_field_tag "viaje_id", @viaje.id %>
			<%= hidden_field_tag "tipoVenta", @mensaje == "RESERVA" ? "Reserva" : "Directa" %>
			<% @nro_documento.each_pair do |nd1, nd2| %>
				<%= hidden_field_tag "nro_documento[#{nd1}]", nd2 %>
			<% end %>
			<% @nombre.each_pair do |n1, n2| %>
				<%= hidden_field_tag "nombre[#{n1}]", n2 %>
			<% end %>
			<% @ape_pat.each_pair do |ap1, ap2| %>
				<%= hidden_field_tag "ape_pat[#{ap1}]", ap2 %>
			<% end %>
			<% @ape_mat.each_pair do |am1, am2| %>
				<%= hidden_field_tag "ape_mat[#{am1}]", am2 %>
			<% end %>
			<% @tipo_comida.each_pair do |tc1, tc2| %>
				<%= hidden_field_tag "tipo_comida[#{tc1}]", tc2 %>
			<% end %>
			<% @genero_pelicula.each_pair do |gp1, gp2| %>
				<%= hidden_field_tag "genero_pelicula[#{gp1}]", gp2 %>
			<% end %>
			<% @asiento.each_pair do |a1, a2| %>
				<%= hidden_field_tag "asiento[#{a1}]", a2 %>
			<% end %>
			<% @tipo_doc.each_pair do |td1, td2| %>
				<%= hidden_field_tag "tipo_doc[#{td1}]", td2 %>
			<% end %>
			<%= hidden_field_tag "promocion_id", @promocion.size > 0 ? @promocion[0].id : -1 %>
		<% end %>
	<% end %>
<% end %>
